﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;

public partial class TiJiao : System.Web.UI.Page
{
    private static string sqlconn = System.Configuration.ConfigurationManager.AppSettings["strConn"].ToString().Trim();
    protected void Page_Load(object sender, EventArgs e)
    {
        txtk_name.Focus();
        if (!IsPostBack)
        {
            BindArea();
        }
    }
    protected void btnTiJiao_Click(object sender, EventArgs e)
    {
        {
            string name = txtk_name.Text.Trim();
            string sex = txtk_sex.Text.Trim();
            string year = Dropk_year.SelectedItem.Text.Trim();
            string month=Dropk_month.SelectedItem.Text.Trim();
            string day = Dropk_date.SelectedItem.Text.Trim();
            string ph = txtk_phone.Text.Trim();
            string area = Dropk_date.SelectedItem.Text.Trim();
            string street = Dropstreet.SelectedItem.Text.Trim();
            string address = txtk_XXaddress.Text.Trim();

            if (month.Length == 1)
            {
                month = "0" + month;
            }
            if (day.Length == 1)
            {
                day = "0" + day;
            }

            SqlConnection conn = new SqlConnection(sqlconn);
            try
            {
                conn.Open();
                string num;
                num=Session["man_m_id"].ToString();
                string sql = "insert into kinder values('"+ num +"','"+name+"','"+sex+"','"+year+month+day+"','"+ph+"','"+area+"','"+street+"','"+address+"')";
                SqlCommand comm = new SqlCommand(sql, conn);
                comm.ExecuteNonQuery();
                Response.Write("<script>alert(\"恭喜你，提交成功！\")</script>");
            }
            catch (SqlException ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                conn.Close();
            }
        }
    }


    void BindArea()
    {
        SqlConnection conn = new SqlConnection(sqlconn);
        try
        {
            string sql = "select * from T_area";
            SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            adp.Fill(ds, "province");
            Dropk_area.DataSource = ds.Tables[0].DefaultView;
            Dropk_area.DataTextField = "FName";
            Dropk_area.DataValueField = "FID";
            Dropk_area.DataBind();
        }
        catch (SqlException ex)
        {
            throw new Exception(ex.Message);
        }
        finally { }
    }
    void BindStreet(string proid)
    {
        SqlConnection conn = new SqlConnection(sqlconn);
        try
        {
            string sql = "select * from T_street where proID='" + proid + "'";
            SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            adp.Fill(ds, "c");
            Dropstreet.DataSource = ds.Tables[0].DefaultView;
            Dropstreet.DataTextField = "FcityName";
            Dropstreet.DataValueField = "FcityID";
            Dropstreet.DataBind();
        }
        catch (SqlException ex)
        {
            throw new Exception(ex.Message);
        }
        finally { }
    }
    protected void Dropk_area_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindStreet(Dropk_area.SelectedValue.Trim());
    }

    protected void Dropstreet_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}